<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="queryParams.userNameCn"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="客户姓名" align="center" prop="userNameCn" />
      <el-table-column label="操作类型" align="center" prop="type" >
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">登录</span>
          <span v-if="scope.row.type == 2">登出</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">成功</span>
        </template>
      </el-table-column>
      <el-table-column label="操作IP" align="center" prop="ip" />
      <el-table-column label="位置" align="center" prop="" >
        <template slot-scope="scope">
            <span v-if="scope.row.country" v-text="scope.row.country"></span>
            <span v-if="scope.row.region">-{{scope.row.region}}</span>
            <span v-if="scope.row.city">-{{scope.row.city}}</span>
            <span v-if="scope.row.county">-{{scope.row.county}}</span>
        </template>
      </el-table-column>
      <el-table-column label="User-Agent" align="center" prop="userAgent" />
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import Template from "@/views/system/mailTemplate";

import { listCustomerLoginLog } from "@/api/system/customerLoginLog";

export default {
  name: "Customer",
  components: {Template},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户端用户表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userNameCn: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客户端用户列表 */
    getList() {
      this.loading = true;
      listCustomerLoginLog(this.queryParams).then(response => {
        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

  }
};
</script>
